<?php
namespace Admin\Model;
use Think\Model;
class UserModel extends Model{
	protected $_validate = array(
			array('name','isName','用户名已经存在',self::MODEL_BOTH, 'callback'),
			array('phone_number','isPhoneNum','用户手机号码格式错误或者该手机号码已被注册',self::MODEL_BOTH,'callback'),
	);
	protected $_auto = array(
			array('password','md5',self::MODEL_BOTH,'function'),
			array('ctime','time',self::MODEL_INSERT,'function'),	
	);
	protected function isName($name){
		$result = M('User')->where(array('name'=>$name))->find();
		if(isset($result)){
			return false;
		}else{
			return true;
		}
	}
	protected function isPhoneNum($phoneNum){
		if(preg_match("/^1\\d{10}$/",$phoneNum)){
			$result = M('User')->where(array('phone_number'=>$phoneNum))->find();
			if(isset($result)){
				return false;
			}else{
				return true;
			}
		}else{
			return false;
		}
	}
}
?>